package com.satoken.ignore;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ignore")
public class SaIgnoreController {


    @RequestMapping("/logoutById")
    public SaResult logout() {
        String loginDevice = StpUtil.getTokenValueByLoginId("1001", "pc");
        return SaResult.ok(loginDevice);
    }

    @RequestMapping("/disable")
    public SaResult disable() {
        StpUtil.kickout("1001", "pc");
        StpUtil.disable("1001", -1);
        return SaResult.ok("封禁1001成功");
    }

    @RequestMapping("/checkDisable")
    public SaResult checkDisable() {
        StpUtil.checkDisable("1001");
        return SaResult.ok("1001已封禁");
    }

    @RequestMapping("/untieDisable")
    public SaResult untieDisable() {
        StpUtil.untieDisable("1001");
        return SaResult.ok(String.valueOf(StpUtil.getDisableTime("1001")));
    }

    @RequestMapping("/disableService")
    public SaResult disableService() {
        StpUtil.disable(StpUtil.getLoginId(), "user.get", -1);
        return SaResult.ok("封禁user.get权限成功");
    }

    @RequestMapping("/searchTokenValue")
    public SaResult searchTokenValue() {
        List<String> searchTokenValue = StpUtil.searchTokenValue("", 0, 10, true);
        for (String string : searchTokenValue) {
            int size = StpUtil.getTokenSessionByToken(string).getTokenSignList().size();
            System.out.println(size);
        }
        return SaResult.data(searchTokenValue);
    }



    public static void main(String[] args) throws Exception {


/*
        加密
       System.out.println(SaSecureUtil.md5("123456"));
        System.out.println(SaSecureUtil.sha1("123456"));
        System.out.println(SaSecureUtil.sha256("123456"));

        // 定义秘钥和明文
        String key = "123456";
        String text = "Sa-Token 一个轻量级java权限认证框架";
        String aesEncrypt = SaSecureUtil.aesEncrypt(key, key + text);
        System.out.println(aesEncrypt);
        System.out.println(SaSecureUtil.aesDecrypt(key, aesEncrypt));

        // 定义私钥和公钥
        String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAO+wmt01pwm9lHMdq7A8gkEigk0XKMfjv+4IjAFhWCSiTeP7dtlnceFJbkWxvbc7Qo3fCOpwmfcskwUc3VSgyiJkNJDs9ivPbvlt8IU2bZ+PBDxYxSCJFrgouVOpAr8ar/b6gNuYTi1vt3FkGtSjACFb002/68RKUTye8/tdcVilAgMBAAECgYA1COmrSqTUJeuD8Su9ChZ0HROhxR8T45PjMmbwIz7ilDsR1+E7R4VOKPZKW4Kz2VvnklMhtJqMs4MwXWunvxAaUFzQTTg2Fu/WU8Y9ha14OaWZABfChMZlpkmpJW9arKmI22ZuxCEsFGxghTiJQ3tK8npj5IZq5vk+6mFHQ6aJAQJBAPghz91Dpuj+0bOUfOUmzi22obWCBncAD/0CqCLnJlpfOoa9bOcXSusGuSPuKy5KiGyblHMgKI6bq7gcM2DWrGUCQQD3SkOcmia2s/6i7DUEzMKaB0bkkX4Ela/xrfV+A3GzTPv9bIBamu0VIHznuiZbeNeyw7sVo4/GTItq/zn2QJdBAkEA8xHsVoyXTVeShaDIWJKTFyT5dJ1TR++/udKIcuiNIap34tZdgGPI+EM1yoTduBM7YWlnGwA9urW0mj7F9e9WIQJAFjxqSfmeg40512KP/ed/lCQVXtYqU7U2BfBTg8pBfhLtEcOg4wTNTroGITwe2NjL5HovJ2n2sqkNXEio6Ji0QQJAFLW1Kt80qypMqot+mHhS+0KfdOpaKeMWMSR4Ij5VfE63WzETEeWAMQESxzhavN1WOTb3/p6icgcVbgPQBaWhGg==";
        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDvsJrdNacJvZRzHauwPIJBIoJNFyjH47/uCIwBYVgkok3j+3bZZ3HhSW5Fsb23O0KN3wjqcJn3LJMFHN1UoMoiZDSQ7PYrz275bfCFNm2fjwQ8WMUgiRa4KLlTqQK/Gq/2+oDbmE4tb7dxZBrUowAhW9NNv+vESlE8nvP7XXFYpQIDAQAB";

        String rsaEncryptByPublic = SaSecureUtil.rsaEncryptByPublic(publicKey, text);
        System.out.println("公钥加密:" + rsaEncryptByPublic);

        String rsaDecryptByPublic = SaSecureUtil.rsaDecryptByPrivate(privateKey, rsaEncryptByPublic);
        System.out.println("私钥解密:" + rsaDecryptByPublic);

        System.out.println(SaSecureUtil.rsaGenerateKeyPair().toString());
        String encode = SaBase64Util.encode(text);
        System.out.println(encode);
        System.out.println(SaBase64Util.decode(encode));
        String hashpw = BCrypt.hashpw("123456", BCrypt.gensalt(30));
        System.out.println(hashpw);
        System.out.println(BCrypt.checkpw("123456", hashpw));*/
    }
}
